package com.itfenghuang.util;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

@Component("tmi")
public class LoginAdvice {
    //环绕通知
    public Result aroundAdvice(ProceedingJoinPoint pdj){
        try{
            System.out.println("进入aop成功");
            //从请求头获取我们的token
            String token = ServletApiUtil.getRequest().getHeader("token");
            if (ObjectUtils.isEmpty(token)){
                return new Result(false,201,"未登录");
            }else {
                Object[] args = pdj.getArgs();
                Result proceed = (Result) pdj.proceed(args);
                System.out.println("登录成功");
                return proceed;
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return null;
    }
}
